/**
 * @param {string[]} words
 * @param {number} k
 * @return {string[]}
 */
var topKFrequent = function (words, k) {
  words.sort()
  let map = new Map()
  let res = []
  for (let i = 0; i < words.length; i++) {
    if (!map.has(words[i])) {
      map.set(words[i], 1)
    } else {
      map.set(words[i], map.get(words[i]) + 1)
    }
  }
  
 res =[...map.entries()]


  res.sort((a,b)=>{
    if(a[1]!=b[1]) return b[1]-a[1]
    else return 
  })
  // console.log('1');
  return res.slice(0,k).map(item=>item[0])
}

topKFrequent(["i", "love", "leetcode", "i", "love", "coding"])
let a = ['2+i', '1+love', 'leetcode', '2+i', '1+love', 'coding']
// a.sort()
// console.log(a)
